package com.jinniulive.platform.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.jinniulive.platform.R;
import com.jinniulive.platform.bean.NewsListInfo;

import java.util.List;

/**
 * Created by Administrater on 2016/12/13.
 */

public class NewsGridViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<NewsListInfo.NewsdataBean.NewsBean> mData;
    public NewsGridViewAdapter(Context context){
        mContext=context;
    }
    public void setData(List<NewsListInfo.NewsdataBean.NewsBean> data){
        mData=data;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mData!=null?mData.size():0;
    }

    @Override
    public Object getItem(int i) {
        return mData!=null?mData.get(i):null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        GridViewHolder holder;
        if(view==null){
            view=LayoutInflater.from(mContext).inflate(R.layout.item_news_gridview,viewGroup,false);
            holder=new GridViewHolder(view);
            view.setTag(holder);
        }else {
            holder = (GridViewHolder) view.getTag();
        }

        NewsListInfo.NewsdataBean.NewsBean newsBean = mData.get(i);
        Glide.with(mContext).load(newsBean.getPicurl()).centerCrop().into(holder.iv_logo);
        holder.tv_title.setText(newsBean.getTitle());
        holder.tv_createDate.setText(newsBean.getCreateDateTime());

        return view;
    }
    class GridViewHolder{
        ImageView iv_logo;
        TextView tv_title;
        TextView tv_createDate;
        GridViewHolder(View view){
            iv_logo= (ImageView) view.findViewById(R.id.iv_news_logo);
            tv_title= (TextView) view.findViewById(R.id.tv_news_title);
            tv_createDate= (TextView) view.findViewById(R.id.tv_news_createDate);
        }
    }
}


